﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ClientRegister
{
    public partial class ChangeCourseForm : Form
    {
        public string IdCourse { set; get; }
        public string NameCoure { set; get; }
        public string Startday { set; get; }
        public string AcceptRegis { set; get; }
        public string NoteCour { set; get; }

        public string IDEmp { set; get; }
        public string NameEmp { set; get; }

        //string xmlDelete = "";


        SynchronizeData sync = new SynchronizeData();

        public ChangeCourseForm()
        {
            InitializeComponent();
        }

        private void ChangeCourseForm_Load(object sender, EventArgs e)
        {
            //Load thông tin của khóa học
            txtNameCourse.Text = NameCoure;
            txtStartDate.Text = DateTime.Parse(Startday).ToShortDateString();
         //   txtNote.Text = NoteCour;
            if (int.Parse(AcceptRegis) == 1)
                chkAccept.Checked = true;
            else chkAccept.Checked = false;

        ////Load du lieu tu server
        //    sync.GetDataForInsertMethodWithID(sync.CourTb, sync.insertcol);
        //    sync.GetDataForUpdateMethodWithID(sync.CourTb, sync.updatecol);
            
        }


        private void btnOk_Click(object sender, EventArgs e)
        {
            ////Load du lieu can update
            ////Load du lieu tu server
            //sync.GetDataForInsertMethodWithID(sync.CourTb, sync.insertcol);
            //sync.GetDataForUpdateMethodWithID(sync.CourTb, sync.updatecol);

            string note = "";
            if (txtNote.Text == "")
                MessageBox.Show("Hãy ghi chú thông tin chỉnh sửa!");
            else
            {
                note += NoteCour + "\n";

                note += "- Chinh sua ngay: " + DateTime.Now.ToString() + " Boi nhan vien: ID:" +IDEmp+", Ten NV: "+NameEmp+ "\n";
                note += "- Noi dung: " + txtNote.Text + "\n";
                int regis = 0;
                if (chkAccept.Checked == true) regis = 1;
                else regis = 0;

                if (txtNameCourse.Text != NameCoure)
                    note += "- " + NameCoure + "\n";
                if (txtStartDate.Text != Startday)
                    note += "- " + Startday + "\n";
                if (int.Parse(AcceptRegis) != regis)
                    note += "- " + AcceptRegis + "\n";

                CourseDataProvider change = new CourseDataProvider();
                
                int result = change.ChangeInfoCourse(IdCourse, txtNameCourse.Text, txtStartDate.Text, regis.ToString(), note);
                
                //string xml = change.ConvertInfoCourseToXml(IdCourse);
                
                if (result == 1)
                {
                  ////Chuyen du lieu len server  
                  //  sync.transfDataForUpdateMethod(xml, sync.CourTb);

                    MessageBox.Show("Chỉnh sửa thành công");
                }
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
